home *** CD-ROM | disk | FTP | other *** search
- Path: frco.com!usenet
- From: Jadam@tcmail.frco.com (Jim Adam)
- Newsgroups: comp.lang.c++
- Subject: Re: Q: what's wrong?
- Date: 5 Feb 1996 19:39:58 GMT
- Organization: Fisher Rosemount Systems
- Message-ID: <4f5mee$e5p@rolaids.frco.com>
- References: <4ejerd$r84@news.infoserve.net>
- NNTP-Posting-Host: primrose.frco.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.11
-
- In article <4ejerd$r84@news.infoserve.net>, paveltka@unix.infoserve.net
- says...
-
-
- > c=*ptr;
- > while((c>=48&&c<=57)||//while c is digit,-,+ or .
- > (c==43)||
- > (c==45)||
- > (c==46))
- > {
- > c= *ptr;
-
- >>> strcat(szC,&c); // RUN-TIME ERROR -- SEE BELOW
-
- > *(szC + strlen(szC)-1)=*"\0";
- > ptr++;
- > }
- > strcpy(szRest,ptr-1);
- > *strpbrk(szC,"XYZR")=*"\0";//to eliminate X,Y,Z at the end of
- > //the szC
- > dC=atof(szC);
-
-
- The following should *not* work:
-
- strcat( szC, &c );
-
- Note that strcat() expects to receive a null-terminated string,
- not just a pointer to a lone character. This will *occassionaly*
- fail mysteriously....
-
- In this case, I'd suggest something like:
-
- int curPos = 0;
- while( .... )
- {
- szC[curPos] = *ptr;
- curPos++;
- ptr++;
- }
- szC[curPos] = 0; // NULL TERMINATE BUFFER
-
- // DO REST OF PROCESSING
-
-
- You might also want to add some error checking to the while()
- condition. I.e.,
-
- while( ... && curPos < sizeof( szC ))
-
- to ensure you don't accidentally overrun the small buffer.
-
- Hope this helps,
-
- Jim
- Jadam@tcmail.frco.com
-
-